1692B - All Distinct - CodeForces Solution


greedy sortings *800

Please click on ads to support us..

Python Code:

n = int(input())
def tekrar(l):
    l2 = []
    for i in range(len(l)):
        if l[i] not in l2:
            l2.append(l[i])
    return l2
def ye(l,l2):
    l3 = [ ]
    for i in range(len(l2)):
        l3.append(l.count(l2[i]))
    return l3
list_khali = []
for i in range(n):
    x = int(input())
    l = [int(i) for i in input().split()]
    l2 = tekrar(l)
    l3 = ye(l,l2)
    t = sum(l3) - len(l3)
    if t % 2 == 0 :
        list_khali.append(len(l2))
    else:
        list_khali.append(len(l2)-1)
for i in list_khali:
    print(i)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dbl double
#define str string
#define f first
#define s second
void solve(){

ll t;
cin >> t;
while( t-- ){
    ll n;
    cin >> n;
    ll a[100000];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }ll k=0;
    sort(a , a+n);
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){k++;}


    }if(k==0)cout << n << endl;

else if (k%2==0) {cout <<n-k << endl;}
	else cout <<n- k- 1 << endl;}}
 int main(){
 solve();}


Comments

Submit
0 Comments
More Questions

1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers